//
//  CHBottomSelectCell.swift
//  jyzx
//
//  Created by cyptt on 2022/5/12.
//

import UIKit
import SnapKit
public class CHSheetCell: UITableViewCell {

    var cellModel:CHSheetModel?
  public  override func awakeFromNib() {
        super.awakeFromNib()
       
        self.setUI()
    }
   public  override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setUI(){
        
    
        self.contentView.addSubview(self.titleL)
        self.contentView.addSubview(self.gougouImagev)
        self.contentView.addSubview(self.lineView)
        self.selectionStyle = .none
        
        
        self.titleL.snp.makeConstraints { make in
            make.left.equalTo(self).offset(5)
            make.centerY.equalToSuperview()
            make.right.equalTo(self).offset(-5)
        
        }
        
        self.gougouImagev.snp.makeConstraints { make in
            make.right.equalTo(self).offset(-5)
            make.centerY.equalToSuperview()
        }
        
        self.lineView.snp.makeConstraints { make in
            make.left.equalTo(self).offset(0)
            make.right.equalTo(self).offset(0)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }
  
    lazy var titleL = {()->UILabel in
        let label = UILabel.init()
        
    
        label.text = ""
        label.textColor = UIColor.init(red: 84/255.0, green: 87/255.0, blue: 94/255.0, alpha: 1)
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    }()
    
    lazy var gougouImagev = {()->UIImageView in
        let imgV = UIImageView.init()
        
        
        return imgV
    }()
    
    lazy var lineView = {()->UIView in
        let v = UIView.init()
        v.backgroundColor = UIColor.clear
        return v
    }()
    
  public  override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    
        if selected == true{
            print("选择了")
            self.gougouImagev.isHidden = false
            
            self.contentView.backgroundColor = self.cellModel?.clickCellBgColor
            self.contentView.layer.borderColor = self.cellModel?.clickBorderColor?.cgColor
            self.contentView.layer.borderWidth = 0.5
            self.contentView.layer.masksToBounds = true
            self.contentView.layer.cornerRadius = 10
        }else{
            self.gougouImagev.isHidden = true
          
            self.contentView.backgroundColor = UIColor.white
            
            self.contentView.layer.borderColor = UIColor.white.cgColor
            self.contentView.layer.borderWidth = 0
            self.contentView.layer.masksToBounds = false
            self.contentView.layer.cornerRadius = 0
        }
        print("进来了---")
        // Configure the view for the selected state
    }
    
    
    public func setBottomSelectMolde(model:CHSheetModel?){
        self.cellModel = model
        
        self.titleL.text = model?.titleName
        self.gougouImagev.image = model?.rSelectedImage
        self.titleL.textAlignment = model?.textAlignment ?? .left
        self.lineView.backgroundColor = model?.lineColor ?? UIColor.clear
    }
}
